package org.linlinjava.litemall.admin.web;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.linlinjava.litemall.admin.annotation.RequiresPermissionsDesc;
import org.linlinjava.litemall.admin.service.AdminLiquorService;
import org.linlinjava.litemall.admin.service.AdminLiquorTopicService;
import org.linlinjava.litemall.core.validator.Order;
import org.linlinjava.litemall.core.validator.Sort;
import org.linlinjava.litemall.db.domain.ILiquormallLiquor;
import org.linlinjava.litemall.db.domain.IliquormallTopic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

@RestController
@RequestMapping("/admin/liquor/liquor")
@Validated
public class AdminLiquorController {
    private final Log logger = LogFactory.getLog(AdminLiquorController.class);

    @Autowired
    private AdminLiquorService adminLiquorService;

    /**
     * 删除酒友圈
     *
     * @param liquor
     * @return
     */
    @RequiresPermissions("admin:liquor:delete")
    @PostMapping("/delete")
    public Object delete(@RequestBody ILiquormallLiquor liquor) {
        return adminLiquorService.delete(liquor);
    }

    /**
     * 查询酒友圈
     *
     * @param title
     * @param page
     * @param limit
     * @param sort
     * @param order
     * @return
     */
    @RequiresPermissions("admin:liquorTopic:read")
    @RequiresPermissionsDesc(menu = {"咨询管理", "咨询列表"}, button = "查询")
    @GetMapping("/list")
    public Object list(String title,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "20") Integer limit,
                       @Sort @RequestParam(defaultValue = "add_time") String sort,
                       @Order @RequestParam(defaultValue = "desc") String order) {
        return adminLiquorService.list(title, page, limit, sort, order);
    }

}
